package com.lbjhan.rpc.consumer.service;

import com.lbjhan.rpc.api.UserService;
import com.lbjhan.rpc.pojo.User;
import com.lbjhan.rpc.consumer.anno.RpcService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@RpcService
@Service
public class UserServiceImpl implements UserService {

    static Map<Integer, User> map = new HashMap<>();

    @Override
    public User getById(Integer id) {
        if(map.size() == 0){
            map.put(1, new User(1, "张飞"));
            map.put(2, new User(2, "关羽"));
            map.put(3, new User(3, "刘备"));
            map.put(4, new User(4, "赵云"));
        }
        return map.get(id);
    }

    @Override
    public User changeNameById(Integer id, String name) {
        if(map.get(id) == null)
            return null;
        map.get(id).setName(name);
        return map.get(id);
    }
}
